package com.dries.portal.listener;

import com.dries.portal.module.coupon.service.IRabbitMqServices;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Description: 注册消费者
 * @Author ZSY
 * @createTime 2020/8/3 18:16
 */
@Slf4j
@Component
public class TopicReceiver {

    @Resource
    private IRabbitMqServices iRabbitMqServices;

    @RabbitListener(queues = "coupon")
    public void couponHandler(String message) {
        iRabbitMqServices.consumeCouponRabbitMqMsg(message);
    }

    @RabbitListener(queues = "convener")
    public void convenerHandler(String message) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = formatter.format(LocalDateTime.now());
        System.out.println("消息接收时间:" + format);
        System.out.println("接收到的消息:" + message);
    }

}
